package com.cet.base;

import java.util.concurrent.TimeUnit;

public class InterruptDemo3 {

    public static void main(String[] args) {

        final Thread t1 = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println(Thread.currentThread().getName() + "\t 中断标志为被修改为true,线程终止！");
                    break;
                }
                System.out.println("t1---------hello interrupt");
            }
        }, "t1");
        t1.start();

        try {
            TimeUnit.MILLISECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            t1.interrupt();
        },"t2").start();
    }
}
